package actions;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import bean.CreateAktieFormBean;

public class CreateAktieAction extends Action{

	@Override
	public String execute(HttpServletRequest request, HttpSession s)
			throws Exception {

		String name 		= "";
		String kuerzel 		= "";
		String nominalpreis = "";
		String dividende 	= "";
		String stueckzahl 	= "";		
		try {
			name = new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
			kuerzel = new String(request.getParameter("kuerzel").getBytes("ISO-8859-1"),"UTF-8");
			nominalpreis = new String(request.getParameter("nominalpreis").getBytes("ISO-8859-1"),"UTF-8");
			dividende = new String(request.getParameter("dividende").getBytes("ISO-8859-1"),"UTF-8");
			stueckzahl = new String(request.getParameter("stueckzahl").getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		if (name.equals("")
				|| kuerzel.equals("")
				|| nominalpreis.equals("")
				|| dividende.equals("")
				|| stueckzahl.equals("")){
			
			setApplicationMessage(s, getMessageProperty("angabenNichtKomplett"));
			return getForwardProperty("createAktie");
		}
		else{			
			saveObjectinSession(request, "createAktieFormBean", new CreateAktieFormBean(name, kuerzel, nominalpreis, dividende, stueckzahl));
			return getForwardProperty("createAktieBestaetigung");
			
		}
		
	}

	
	
}
